<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import ReCol from "@/components/ReCol";
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    title: "",
    status: 0,
    Id: 0,
    dispatchOrderId: 0,
    dateTime: null,
    remarks: "",
    storageOrderId: 0,
    vehicleList: []
  })
});
const statusOptions = [
  {
    value: 1,
    label: "有效"
  },
  {
    value: 2,
    label: "无效"
  },
  {
    value: 3,
    label: "已完成"
  }
];
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}
defineExpose({ getRef });
function setRangeTime() {
  return true;
}
import { useColumns } from "./utils/columns";
const { columns, dataList, onAdd, onDel } = useColumns();
import Empty from "./utils/empty.svg?component";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import AddFill from "@iconify-icons/ep/plus";
import Delete from "@iconify-icons/ep/delete";
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="auto"
  >
    <el-row :gutter="30">
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="发货订单id" prop="dispatchOrderId">
          <el-input
            v-model="newFormInline.dispatchOrderId"
            clearable
            placeholder="请选择发货订单id"
          />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24" prop="dateTime">
        <el-form-item label="存货日期">
          <el-date-picker
            v-model="newFormInline.dateTime"
            type="daterange"
            class="!w-[240px]"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            :popper-options="{
              placement: 'bottom-start'
            }"
            value-format="YYYY-MM-DD"
            @change="setRangeTime()"
          />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="状态" prop="status">
          <el-select
            v-model="newFormInline.status"
            placeholder="请选择状态"
            class="w-full"
            clearable
          >
            <el-option
              v-for="(item, index) in statusOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="存货备注" prop="remarks">
          <el-input
            v-model="newFormInline.remarks"
            placeholder="日程详情"
            type="textarea"
          />
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <el-form-item label="商品信息" prop="goodsList">
          <pure-table
            row-key="id"
            align-whole="center"
            :header-cell-style="{
              background: 'var(--el-fill-color-light)',
              color: 'var(--el-text-color-primary)'
            }"
            :data="dataList"
            :columns="columns"
          >
            <template #empty>
              <Empty fill="var(--el-svg-monochrome-grey)" class="m-auto" />
            </template>
            <template #append>
              <el-button
                plain
                class="w-full my-2"
                :icon="useRenderIcon(AddFill)"
                @click="onAdd"
              >
                添加一行数据
              </el-button>
            </template>
            <template #operation="{ row }">
              <el-button
                class="reset-margin"
                link
                type="primary"
                :icon="useRenderIcon(Delete)"
                @click="onDel(row)"
              />
            </template>
            <template #hobby>
              <el-select
                ref="selectRef"
                class="!w-[600px]"
                placeholder="请选择"
                value-key="corpId"
                clearable
              >
                <template #empty>
                  <div class="m-4">
                    <pure-table
                      row-key="corpId"
                      alignWhole="center"
                      :header-cell-style="{
                        background: 'var(--el-fill-color-light)',
                        color: 'var(--el-text-color-primary)'
                      }"
                      :data="dataList"
                      :columns="columns"
                    />
                  </div>
                </template>
              </el-select>
            </template>
          </pure-table>
        </el-form-item>
      </re-col>
      <re-col :value="24" :xs="24" :sm="24">
        <code>
          <pre> {{ dataList }}</pre>
          ;
        </code>
      </re-col>
    </el-row>
  </el-form>
</template>
<style scoped>
:deep(.el-table__inner-wrapper::before) {
  height: 0;
}
</style>
